<?php
namespace app\common\model;
use think\Model;
class System extends Model{


    //get system configration
    public function sysConfig()
    {
        $res=$this->find();
        return $res;
    }

    /**
     * 当前实时挑战金额
     */
    public function curmoney(){
        $projectitem = model('Projectitem');
        $res = $projectitem->getdayItem();
        $arr = $this->head_img($res);
        $cur_per = count($res);
        $totalmoney = 0;
        foreach ($res as $k=>$v){
            $totalmoney += $v['join_money'];
        }
        db('system')->update(array('cur_money'=>$totalmoney,'id' =>1));
        db('system')->update(array('cur_per'=>$cur_per,'id' =>1));
        return $arr;
    }

    /**
     * @param $res
     * @return array
     * 获取打卡的头像
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function head_img($res){
//        $data = db('projectitem')->order('create_time','desc')->select();
        $result = array_slice($res,0,13);
//        halt($result);
        $user = model('User');
        $arr= [];
        foreach ($result as $k=>$v){
          $result = $user->find($v['uid']);
          $arr[] = $result;
        }
        return $arr;
    }


}